package com.hoopchina.weibo.http;
import org.json.JSONException;
import org.json.JSONObject;

import com.hoopchina.weibo.WeiboException;
import com.hoopchina.weibo.WeiboType;

/**
 * 
 * @author neusoft
 *
 */
public class User{
    private String mName = "";
    private String mScreenName = "";
    private String mProfileImageUrl = "";
    
    public User( String resStr, int type ) throws WeiboException {
	    try {    	
	    	JSONObject root = new JSONObject( resStr );
	    	switch( type )
	    	{
	    		case WeiboType.SinaType:
	    		case WeiboType.SohuType:
					mScreenName = root.getString( "screen_name" ).trim();
					mProfileImageUrl = root.getString( "profile_image_url" ).trim();
				break;
	    		case WeiboType.TencentType:
	    			JSONObject dataObj = root.getJSONObject("data");
					mScreenName = dataObj.getString( "nick" ).trim();
					mProfileImageUrl = dataObj.getString("head").trim() + "/50";
	    		break;
	    		case WeiboType.NetEaseType:
	    			mScreenName = root.getString( "name" ).trim();
	    			mProfileImageUrl = root.getString( "profile_image_url" ).trim();
	    		break;
	    	}
		} catch (JSONException e) {
			e.printStackTrace();
		}
    }

    public String getName() {
        return mName;
    }

    public String getScreenName() {
        return mScreenName;
    }

    public String getProfileImageURL() {
    	return mProfileImageUrl;
    }
}
